from bokeh.models import Select, CustomJS, ColumnDataSource
from bokeh.layouts import column
from numpy import number
x_value = 'goals'
y_value = 'birth_month_number'
full_source = ColumnDataSource(nhl_player_stats_team_df)
source = ColumnDataSource(
data=dict(
x=nhl_player_stats_team_df[x_value],
y=nhl_player_stats_team_df[y_value],
)
)
plot = figure(width=400, height=200, title="test")
plot.circle(
'x',
'y',
source=source,
fill_alpha=0.2,
size=1
)
numeric_cols = nhl_player_stats_team_df.select_dtypes([number]).columns.tolist()
x_select = Select(title="X Axis", options=numeric_cols, value=x_value)
x_select.js_on_change("value", CustomJS(args=dict(source=source, data=full_source), code="""
console.log(`this is the selected value: ${this.value}`);
console.log(source.data['x'])
console.log(data.data)
source.data['x'] = data.data[this.value]
source.change.emit();
"""))
layout = column(x_select, plot)
output_file('test.html')
show(layout)